package com.ihooyah;

/**
 * @author 李诚 【licheng@ihooyah.com】
 * @description
 * @create 2017-02-14 下午4:40
 **/
public class MyTestThread implements Runnable {

    private String name;
    private Object prev;
    private Object self;

    public MyTestThread(String name, Object prev, Object self) {
        this.name = name;
        this.prev = prev;
        this.self = self;
    }

    public void run() {
        int count = 10;
        while (count > 0) {
            synchronized (prev) {
                synchronized (self) {
                    System.out.print(name);
                    count--;

                    self.notify();
                }
                try {
                    System.out.print("#");
                    prev.wait();
                    System.out.print("*");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
